package com.cheng.project_model1.config;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import com.cheng.project_model1.config.properties.EnvProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;


/**
 * @author emiyakiri
 */
@Configuration
public class DozerConfig {
    private final EnvProperties envProperties;

    @Autowired
    public DozerConfig(EnvProperties envProperties) {
        this.envProperties = envProperties;
    }

    @Bean
    @Scope("singleton")
    public Mapper dozer() {
        String[] mappingFiles = envProperties.getDozer().resolveMappingLocation();
        DozerBeanMapperBuilder builder = DozerBeanMapperBuilder.create();
        if (mappingFiles != null) {
            builder.withMappingFiles(mappingFiles);
        }
        return builder.build();
    }
}
